package py.com.alfa.escriba.web.rest.impl;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import py.com.alfa.escriba.config.EscribaApplicationContextProvider;
import py.com.alfa.escriba.exception.ServiceException;
import py.com.alfa.escriba.web.rest.EscribaService;
import py.com.alfa.escriba.web.rest.dto.UserResponseDTO;
import py.com.alfa.escriba.web.rest.secure.LoginSecureRESTService;
import py.com.alfa.escriba.web.services.LoginService;

public class LoginSecureRESTServiceImpl implements LoginSecureRESTService {

	private Logger log = LoggerFactory.getLogger(getClass());
	private ApplicationContext ctx;
	private LoginService login;
	
	
	public LoginSecureRESTServiceImpl() {
		this.ctx = EscribaApplicationContextProvider.getContext();
		this.login = (LoginService)this.ctx.getBean(EscribaService.LOGIN_SERVICE);		
	}



	@Override
	public UserResponseDTO validUser(String userName, String clave)	throws ServiceException {
		this.log.debug("===== INI Valida Usuario {}",userName.toUpperCase());
		UserResponseDTO userDTO = this.login.validUser(userName, clave);
        
        userDTO.getUser().setPassword(null);

        this.log.debug("===== FIN Valida Usuario {}",userDTO.toString());
		return userDTO;
	}

}
